<template>
  <div class="collapse-view" @click="handle" :style="{ 'border-bottom': border ? '1px dashed #F0F1F3' : 'none' }">
    <div class="collapse-list" :style="{ 'cursor': type == 1 ? 'pointer' : 'default' }">
      <div class="left">
        <slot name="text"></slot>
      </div>
      <div class="right">
        <i class="el-icon-arrow-right" v-if="type == 1"></i>
        <slot name="custom" v-if="type == 2"></slot>
        <i :class="ifShow ? 'el-icon-caret-top' : 'el-icon-caret-bottom'" v-if="type == 3" @click="collapseEvent"></i>
      </div>
    </div>
    <div class="collapse-content" :class="ifShow ? '' : 'active'" :style="{ 'height': height }" v-if="type == 3">
      <div ref="content">
        <slot name="content"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    type: {
      type: Number,
      default: 1 // 1：点击跳转项，2：展示项，3：折叠面板
    },
    border: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      ifShow: false,
      height: 0
    }
  },
  mounted() {
    if (this.$refs.content) this.height = window.getComputedStyle(this.$refs.content).height
  },
  methods: {
    handle() {
      if (this.type == 1) this.$emit('handle')
    },
    collapseEvent() {
      this.ifShow = !this.ifShow
    }
  }
}
</script>

<style lang="less" scoped>
  .collapse-view{
    padding-right: 5px;
    .collapse-list{
      height: 40px;
      line-height: 40px;
      display: flex;
      justify-content: space-between;
      .left{
        font-size: 12px;
        color: #58657A;
      }
      .right{
        display: flex;
        align-items: center;
        font-size: 12px;
        color: #58657A;
        i{
          font-size: 13px;
        }
        .el-icon-caret-top, .el-icon-caret-bottom{
          color: #7A7F8D;
          cursor: pointer
        }
      }
    }
    .collapse-content{
      padding-left: 24px;
      transition: height .4s;
      overflow: hidden;
    }
    .active{
      height: 0 !important;
      overflow: hidden;
    }
  }
</style>